{
    container_list="$(docker ps -f name="netns-(pppoe|static)-[0-z]{12}" | awk 'NR>1 {print $NF}')"
    for item in ${container_list}; do
        netns_pid="$(docker inspect $item -f '{{.State.Pid}}')"
        read -r -d '' cmd <<'EOF'
interface_name="$(ip -br a | grep -Eo '^ppp[0-z]{12}')"
speed_kbps="$(cat /proc/1/environ -A 2>/dev/null | grep -Eo "MAX_TX=[0-9]*" | awk -F'=' '{print $2}' | awk '{print int($1/8*1024)"kbps"}')"
tc qdisc del dev $interface_name root

tc qdisc add dev $interface_name root handle 1: hfsc default 10
tc class add dev $interface_name parent 1: classid 1:1 hfsc sc rate $speed_kbps ul rate $speed_kbps

tc class add dev $interface_name parent 1:1 classid 1:10 hfsc sc rate 1280mbps ul rate 1280mbps
tc class add dev $interface_name parent 1:1 classid 1:20 hfsc sc rate 1kbps ul rate $speed_kbps

tc filter add dev $interface_name protocol ip parent 1:0 prio 1 u32 match ip sport 4000 0xffff flowid 1:20
tc filter add dev $interface_name protocol ip parent 1:0 prio 1 u32 match ip dport 4000 0xffff flowid 1:20
tc filter add dev $interface_name protocol ip parent 1:0 prio 1 u32 match ip sport 4040 0xffff flowid 1:20
tc filter add dev $interface_name protocol ip parent 1:0 prio 1 u32 match ip dport 4040 0xffff flowid 1:20

EOF
    nsenter --mount=/proc/$netns_pid/ns/mnt --net=/proc/$netns_pid/ns/net bash -c "$cmd"
    done
}

echo "successfully deploy..."

